package designpattern.factorial;

public class LongHandler implements Handler {
    Handler next;

    @Override
    public void setNext(Handler handler) {
        next = handler;
    }

    @Override
    public void handleRequest(int n) {
        long result = 1L;
        for (int i = 2; i <= n; i++) {
            result *= i;
            if (result % i != 0) {
                if (next != null) {
                    next.handleRequest(n);
                    return;
                }
            }
        }
        System.out.println(String.format("%d!=%d", n, result));
    }
}
